﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sunboxsoft.Common;
using System.Data.SQLite;

namespace Sunboxsoft.ASMS.Client.Domain.Service
{
    public class GetService
    {
        /// <summary>
        /// 获得用户资产值
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="assetType">Domain.Constant.AssetType.?</param>
        /// <returns></returns>
        public SingleResult<decimal> GetAsset(Guid customerId, int assetType)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfDecimal result = service.GetAsset(customerId, assetType);
                if (result.IsSuccess)
                {
                    return new SingleResult<decimal>(result.Data);
                }
                return new SingleResult<decimal>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<decimal>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }       

        /// <summary>
        /// 获取预约单详细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SingleResult<WebRef.BookingBillDetail> GetBookingBillDetail(Guid id)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfBookingBillDetail result = service.GetBookingBillDetail(id);
                if (result.IsSuccess)
                {
                    return new SingleResult<WebRef.BookingBillDetail>(result.Data);
                }
                return new SingleResult<WebRef.BookingBillDetail>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<WebRef.BookingBillDetail>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 获取维修单详细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SingleResult<WebRef.MaintenanceBillDetail> GetMaintenanceBill(Guid id)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfMaintenanceBillDetail result = service.GetMaintenanceBillDetail(id);
                if (result.IsSuccess)
                {
                    return new SingleResult<WebRef.MaintenanceBillDetail>(result.Data);
                }
                return new SingleResult<WebRef.MaintenanceBillDetail>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<WebRef.MaintenanceBillDetail>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 获取套餐购买单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SingleResult<WebRef.VPackagePurchaseBill> GetPackagePurchaseBill(Guid id)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfVPackagePurchaseBill result = service.GetPackagePurchaseBill(id);
                if (result.IsSuccess)
                {
                    return new SingleResult<WebRef.VPackagePurchaseBill>(result.Data);
                }
                return new SingleResult<WebRef.VPackagePurchaseBill>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<WebRef.VPackagePurchaseBill>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }
    
        /// <summary>
        /// 通过结算单Id获取结算单信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SingleResult<WebRef.SettlementBillDetail> GetSettlementBillDetail(Guid id)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfSettlementBillDetail result = service.GetSettlementBillDetail(id);
                if (result.IsSuccess)
                {
                    return new SingleResult<WebRef.SettlementBillDetail>(result.Data);
                }
                return new SingleResult<WebRef.SettlementBillDetail>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<WebRef.SettlementBillDetail>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 通过维修单Id获取结算单信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SingleResult<WebRef.SettlementBillDetail> GetSettlementBillDetailByMaintennanceBillId(Guid id)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfSettlementBillDetail result = service.GetSettlementBillDetailByMaintennanceBillId(id);
                if (result.IsSuccess)
                {
                    return new SingleResult<WebRef.SettlementBillDetail>(result.Data);
                }
                return new SingleResult<WebRef.SettlementBillDetail>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<WebRef.SettlementBillDetail>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 获取维修单详细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SingleResult<WebRef.VRechargeBill> GetRechargeBill(Guid id)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfVRechargeBill result = service.GetRechargeBill(id);
                if (result.IsSuccess)
                {
                    return new SingleResult<WebRef.VRechargeBill>(result.Data);
                }
                return new SingleResult<WebRef.VRechargeBill>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<WebRef.VRechargeBill>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 获取库存预警阈值
        /// </summary>
        /// <param name="warehouseId"></param>
        /// <param name="materialId"></param>
        /// <returns></returns>
        public SingleResult<WebRef.VStockThresholdValue> GetStockThresholdValue(Guid warehouseId, Guid materialId)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfVStockThresholdValue result = service.GetStockThresholdValue(warehouseId, materialId);
                if (result.IsSuccess)
                {
                    return new SingleResult<WebRef.VStockThresholdValue>(result.Data);
                }
                return new SingleResult<WebRef.VStockThresholdValue>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<WebRef.VStockThresholdValue>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 获取库存预警阈值
        /// </summary>
        /// <param name="warehouseId"></param>
        /// <param name="materialId"></param>
        /// <returns></returns>
        public SingleResult<WebRef.VCustomer> GetCustomer(Guid id)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfVCustomer result = service.GetCustomer(id);
                if (result.IsSuccess)
                {
                    return new SingleResult<WebRef.VCustomer>(result.Data);
                }
                return new SingleResult<WebRef.VCustomer>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<WebRef.VCustomer>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 获取仓库详细信息
        /// </summary>
        /// <param name="warehouseId"></param>
        /// <param name="materialId"></param>
        /// <returns></returns>
        public SingleResult<WebRef.VWarehouse> GetWarehouse(Guid id)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.SingleResultOfVWarehouse result = service.GetWarehouse(id);
                if (result.IsSuccess)
                {
                    return new SingleResult<WebRef.VWarehouse>(result.Data);
                }
                return new SingleResult<WebRef.VWarehouse>(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new SingleResult<WebRef.VWarehouse>(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }
    }
}
